﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;

namespace GuildofHeroes
{

    class HomeTown
    {
        //Texture2D _TownTexture;
        Vector2 _Position;
        //int _Health = 500;

        float HomeRegen = 1f;
        private int m_Health = 500;
        private GuildofHeroes.AnimatedSprite m_HomeTown = new GuildofHeroes.AnimatedSprite(); 

        public HomeTown(Texture2D pTexture2D, int pPosX, int pPosY, int pNumFrames, int pFrameWidth, int pFrameHeight,
            int pHorizontalSpace, int pVerticalSpace, int pFramesPerSec, float pScale)
        {
            m_HomeTown.LoadSprite(pTexture2D, pPosX, pPosY, pNumFrames, pFrameWidth, pFrameHeight, pHorizontalSpace, pVerticalSpace, pFramesPerSec, pScale);
            _Position = new Vector2(pPosX, pPosY);

        }

        public void Update(GameTime _gameTime, KeyboardState pKeyboardState)
        {
            if (pKeyboardState.IsKeyDown(Keys.H))
                UpdateHealth(true, 10);
            if (pKeyboardState.IsKeyDown(Keys.N))
                UpdateHealth(false, 10);
            m_HomeTown.Update(_gameTime);            

            HomeRegen -= (float)_gameTime.ElapsedGameTime.TotalSeconds;

            if (m_Health < 500 && HomeRegen <=0)
            {                
                m_Health += 1;
                HomeRegen = 1;                
            }
            else if (m_Health >= 500)
                m_Health = 500;
        }

        public void UpdateHealth(bool pDamage, int pAmount)
        {
            if (pDamage)
                m_Health -= pAmount;
            if (!pDamage)
                m_Health += pAmount;
            if (m_Health >= 500)
                m_Health = 500;
            if (m_Health <= 0)
                m_Health = 0;

        }

        public bool isIntact()
        {
            if (m_Health <= 0)
                return false;

            return true;            
        }

        public void Draw(SpriteBatch _spriteBatch)
        {
            m_HomeTown.Draw(_spriteBatch);
        }

        public void UpdatePos(float x, float y)
        {
            m_HomeTown.UpdatePos(x, y);
        }

        public float GetPosX()
        {
            return m_HomeTown.X;
        }

        public float GetPosY()
        {
            return m_HomeTown.Y;
        }

        public int GetHealth()
        {
            return m_Health;
        }

        public int GetHeight()
        {
            return m_HomeTown.GetHeight();
        }

        public int GetWidth()
        {
            return m_HomeTown.GetWidth();
        }

        public Rectangle GetRectangle()
        {
            return m_HomeTown.getRectangle();
        }

        public Vector2 Position()
        {
            return _Position;
        }
    }

}